package com.feng.zhihao.apigeteway.gateway.bean.impl.INTERFACE_FIELD_POSITION.RES;

import org.springframework.stereotype.Component;

import com.feng.zhihao.apigeteway.entity.InterfaceFieldInfo;
import com.feng.zhihao.apigeteway.exception.ExceptionMessage;
import com.feng.zhihao.apigeteway.exception.GetewayException;
import com.feng.zhihao.apigeteway.gateway.ReqContext;
import com.feng.zhihao.apigeteway.gateway.bean.INTERFACE_FIELD_POSITION_RES;
import com.feng.zhihao.apigeteway.util.ParamsUtil;

import ognl.Ognl;
import ognl.OgnlException;

@Component("FIELD_POSITION_RES_PARAMS")
public class FIELD_POSITION_RES_PARAMS implements INTERFACE_FIELD_POSITION_RES {

	@Override
	public void setValue(InterfaceFieldInfo interfaceFieldInfo,Object value, ReqContext reqContext) {
		String path=ParamsUtil.getPath(interfaceFieldInfo);
		try {
			Ognl.setValue(path, reqContext,value);
		} catch (OgnlException e) {
			throw new GetewayException(e,ExceptionMessage.PARAMS_SET_OGNL_EXCEPTION,interfaceFieldInfo.getInterfaceFieldName(),path);
		}
	}

	@Override
	public Object getValue(InterfaceFieldInfo interfaceFieldInfo, ReqContext reqContext) {
		String path=ParamsUtil.getPath(interfaceFieldInfo);
		try {
			return Ognl.getValue(path, reqContext);
		} catch (OgnlException e) {
			throw new GetewayException(e,ExceptionMessage.PARAMS_OGNL_EXCEPTION,interfaceFieldInfo.getInterfaceFieldName(),path);
		}
	}

}
